package com.it.mybytestream2;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ByteStreamDemo2 {
    public static void main(String[] args) throws IOException {
        //1.创建对象
        FileInputStream fis = new FileInputStream("D:\\java\\basic-code\\myio\\src\\a.txt");
        //2.读取数据
        byte[] bytes = new byte[2];
        //一次读取多个字节 数据，具体读取多少，跟数组的长度有关
        //返回值：本次读取到了多少个字节
        int len = fis.read(bytes);
        System.out.println(len);//2
        String str1 = new String(bytes, 0, len);
        System.out.println(str1);//ab

        int len2 = fis.read(bytes);
        System.out.println(len2);//2
        String str2 = new String(bytes, 0, len2);
        System.out.println(str2);//cd

        int len3 = fis.read(bytes);
        System.out.println(len3);//1
        String str3 = new String(bytes, 0, len3);
        System.out.println(str3);//e

        //超出读取，会返回-1

        fis.close();
    }
}
